package com.zryc.shop.sms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zryc.shop.sms.entity.FlashPromotion;
import com.zryc.shop.sms.entity.HomeAdvertise;
import com.zryc.shop.sms.entity.HomeNewProduct;
import com.zryc.shop.sms.mapper.HomeAdvertiseMapper;
import com.zryc.shop.sms.service.IHomeAdvertiseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 首页轮播广告表 服务实现类
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@Service
public class HomeAdvertiseServiceImpl extends ServiceImpl<HomeAdvertiseMapper, HomeAdvertise> implements IHomeAdvertiseService {

    /**
     * 广告列表
     *
     * @param name
     * @param type
     * @param endTime
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Page<HomeAdvertise> list(String name, Integer type, String endTime, Integer pageNum, Integer pageSize) {
        Page<HomeAdvertise> page = new Page<>(pageNum, pageSize);
        QueryWrapper<HomeAdvertise> wrapper = new QueryWrapper<>();

        if (!StringUtils.isEmpty(name)) {
            wrapper.like("name", name);
        }
        if (!StringUtils.isEmpty(endTime)) {
            wrapper.like("end_time", endTime);
        }
        if (type != null) {
            wrapper.eq("type", type);
        }
        return page(page, wrapper);
    }

    /**
     * 修改广告状态
     *
     * @param id
     * @param status
     * @return
     */
    @Override
    public Object updateStatus(Long id, Integer status) {
        UpdateWrapper<HomeAdvertise> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", id);
        updateWrapper.set("status", status);
        update(updateWrapper);
        return null;
    }

    /**
     * 更新广告内容
     *
     * @param id
     * @param advertise
     * @return
     */
    @Override
    public Object updateAdvertise(Long id, HomeAdvertise advertise) {
        UpdateWrapper<HomeAdvertise> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",id);
        baseMapper.update(advertise,updateWrapper);
        return null;
    }
}
